package cn.news.biz;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.news.dao.TopicDao;
import cn.news.entity.Topic;
import cn.news.util.SqlSessionFactoryUtil;

public class TopicBiz {
	
	/**
	 * 增加主贴
	 * @param tname
	 * @return
	 */
	public boolean addTopic(String tname){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		TopicDao tDao=session.getMapper(TopicDao.class);
		int flag=tDao.addTopic(tname);
		if(flag>0){
			return true;
		}else{
			return false;
		}
		
	}
	/**
	 * 查询所有主贴
	 * @return
	 */
	public List<Topic> searchAll(){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		TopicDao tDao=session.getMapper(TopicDao.class);
		return tDao.searchAll();
	}
	/**
	 * 修改主题
	 * @param topic
	 * @return
	 */
	public boolean update(Topic topic){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		TopicDao tDao=session.getMapper(TopicDao.class);
		int flag=tDao.update(topic);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 根据id查内容
	 * @param tid
	 * @return
	 */
	public Topic searchTname(int tid){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		TopicDao tDao=session.getMapper(TopicDao.class);
		return tDao.searchTname(tid);
	}
	
	/**
	 * 删除主题
	 * @param tid
	 * @return
	 */
	public boolean delete(int tid){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		TopicDao tDao=session.getMapper(TopicDao.class);
		int flag=tDao.delete(tid);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}
	
}

